//
//  YDLocalMessageCell.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2018/1/25.
//  Copyright © 2018年 LK-IOS. All rights reserved.


#import "YDLocalMessageCell.h"

@interface YDLocalMessageCell()
/**
 白色背景view
 */
@property (nonatomic, strong)UIView *bgView;


/**
 红点view
 */
@property (nonatomic, strong)UIView *redPoint;

/**
 标题
 */
@property (nonatomic, strong)UILabel *titleLbl;

/**
 日期
 */
@property (nonatomic, strong)UILabel *dateLbl;

/**
 内容
 */
@property (nonatomic, strong)UILabel *textLbl;




@end

@implementation YDLocalMessageCell


- (void)setModel:(YDNotiModel *)model
{
    _model = model;
    
   
    
    
    self.textLbl.text = model.content;
    self.titleLbl.text = model.title;
    if (model.createTime.length) {
        self.dateLbl.text = [model.createTime substringWithRange:NSMakeRange(0, model.createTime.length - 3)];
    }
    
    self.redPoint.hidden = [model.hasRead boolValue];
    
}

+(CGFloat)heightForCellWithModel:(YDNotiModel *)model
{
    CGFloat textH = [NSString getHeightWithText:model.content font:[UIFont systemFontOfSize:LKScreenW *font14ScreenWRate] MaxWidth:LKScreenW - 2*rate375(20) lineSpace:1.5];

    return textH + (isPhoneX ? rateX812(60) :rate750(60));
}

+ (instancetype)cellWithTbaleview:(UITableView *)tableview
{
    static NSString *const PZLocalMessageCellID = @"YDLocalMessageCell";
    
    YDLocalMessageCell *cell = [tableview dequeueReusableCellWithIdentifier:PZLocalMessageCellID];
    if (cell == nil) {
        cell = [[YDLocalMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PZLocalMessageCellID];
        cell.backgroundColor = [UIColor colorWithHexString:mainGray];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self bgView];
        [self titleLbl];
        [self redPoint];
        [self dateLbl];
        [self textLbl];
        
    }
    return self;
}


-(UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 4;
        _bgView.layer.masksToBounds = YES;
        
        [self.contentView addSubview:_bgView];
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(rate375(10)));
            make.right.equalTo(@(-rate375(10)));
            if (isPhoneX) {
                make.top.equalTo(@(rateX812(10)));

            }else
            {
                make.top.equalTo(@(rate750(10)));

         
            }
            make.height.equalTo(self.contentView.mas_height).multipliedBy(0.9);
            
        }];
    }
    return _bgView;
}

-(UILabel *)titleLbl
{
    if (_titleLbl == nil) {
        _titleLbl = [UILabel new];
        _titleLbl.text = @"点买通知";
        _titleLbl.font = [UIFont systemFontOfSize:LKScreenW *font15ScreenWRate];
        [self.contentView addSubview:_titleLbl];
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(rate375(20)));
            make.top.equalTo(_bgView.mas_top).offset(isPhoneX? rateX812(15) : rate750(15));
        }];
    }
    return _titleLbl;
}

-(UIView *)redPoint
{
    if (_redPoint == nil) {
        _redPoint = [UIView new];
        _redPoint.backgroundColor = [UIColor redColor];
        _redPoint.layer.cornerRadius = 4;
        _redPoint.layer.masksToBounds = YES;
        [self.contentView addSubview:_redPoint];
        [_redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_titleLbl.mas_left).offset(2);
            make.top.equalTo(_titleLbl.mas_top);
            make.width.height.equalTo(@8);
        }];
        
    }
    return _redPoint;
}

-(UILabel *)dateLbl
{
    if (_dateLbl == nil) {
        _dateLbl = [UILabel new];
        _dateLbl.text = @"2017.12.27  14:11";
        _dateLbl.textAlignment = NSTextAlignmentRight;
        _dateLbl.font = [UIFont systemFontOfSize:LKScreenW *font12ScreenWRate];
        [self.contentView addSubview:_dateLbl];
        [_dateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_bgView).offset(-rate375(10));
            make.centerY.equalTo(_titleLbl.mas_centerY);
        }];
    }
    return _dateLbl;
}

-(UILabel *)textLbl
{
    if (_textLbl == nil) {
        _textLbl = [UILabel new];
        _textLbl.textColor = [UIColor colorWithHexString:battleshipGrey];
        _textLbl.lineBreakMode = NSLineBreakByCharWrapping;
        _textLbl.text = @"您所购买的“中国平安000001”已经入“持仓中”状态，点击 查看详情>";
        _textLbl.numberOfLines = 0;
        _textLbl.font = [UIFont systemFontOfSize:LKScreenW *font14ScreenWRate];
        [self.contentView addSubview:_textLbl];
        [_textLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_titleLbl.mas_left);
            make.right.equalTo(_dateLbl.mas_right);
            make.top.equalTo(_titleLbl.mas_bottom).offset(isPhoneX? rateX812(8) : rate750(8));

        }];
    }
    return _textLbl;
}
@end
